import java.util.Scanner;

public class SupermarketShopping {
    public static void main(String[] args) {
        // 创建商品清单
        String[] items = {"苹果", "香蕉", "橙子", "西瓜", "葡萄"};
        double[] prices = {2.0, 1.5, 3.0, 5.0, 4.0};
        int[] stock = {10, 15, 8, 5, 12};

        Scanner scanner = new Scanner(System.in);
        boolean continueShopping = true;
        double totalCost = 0.0;

        while (continueShopping) {
            // 显示商品清单
            System.out.println("======= 商品清单 =======");
            for (int i = 0; i < items.length; i++) {
                System.out.println(i + 1 + ". " + items[i] + " - 价格：" + prices[i] + " - 库存：" + stock[i]);
            }
            System.out.println("=======================");

            // 提示用户输入要购买的商品和数量
            System.out.print("请输入要购买的商品编号：");
            int itemIndex = scanner.nextInt() - 1;
            System.out.print("请输入要购买的商品数量：");
            int quantity = scanner.nextInt();

            // 检查用户输入是否有效
            if (itemIndex >= 0 && itemIndex < items.length) {
                // 检查库存是否足够
                if (stock[itemIndex] >= quantity) {
                    // 计算购买的商品总价
                    double itemCost = prices[itemIndex] * quantity;
                    totalCost += itemCost;

                    // 减少相应商品的库存数量
                    stock[itemIndex] -= quantity;

                    // 显示购买的商品信息
                    System.out.println("您购买了 " + items[itemIndex] + " x" + quantity);
                    System.out.println("商品总价为：" + itemCost);
                } else {
                    System.out.println("库存不足！");
                }
            } else {
                System.out.println("请输入有效的商品编号！");
            }

            // 提示用户是否继续购物
            System.out.print("是否继续购物？（是/否）：");
            String choice = scanner.next();

            if (choice.equalsIgnoreCase("否")) {
                continueShopping = false;
            }
        }

        // 显示购物结束的信息和总购物金额
        System.out.println("购物结束！");
        System.out.println("您购买的商品及总购物金额如下：");
        for (int i = 0; i < items.length; i++) {
            System.out.println(items[i] + " - 数量：" + (stock[i] + stock[i]) + " - 价格：" + prices[i]);
        }
        System.out.println("总购物金额为：" + totalCost);
    }
}